package o;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;
import com.huawei.appgallery.appcomment.impl.bean.AddCommentResBean;
import com.huawei.appgallery.appcomment.impl.bean.CommentsCache;
import com.huawei.appgallery.appcomment.ui.CommentActivity;
import com.huawei.appgallery.appcomment.ui.view.AddCommentTitle;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant.KeyAndValue;
import huawei.widget.HwEditText;
import java.lang.ref.WeakReference;
import java.security.SecureRandom;
import o.bcg.h;
import o.bdo.d;

public class bdw implements TextWatcher, OnRatingBarChangeListener {
    private int ʻ;
    private boolean ʻॱ = false;
    private Float ʼ = null;
    private String ʽ = null;
    private String ˊ;
    private RatingBar ˊॱ;
    private String ˋ;
    private CommentActivity ˋॱ;
    private String ˎ;
    private String ˏ;
    private boolean ˏॱ;
    private Context ͺ;
    private String ॱ;
    private HwEditText ॱˊ;
    private AddCommentTitle ॱˋ;
    private String ॱॱ = null;
    private bck ᐝ;
    private String[] ᐝॱ;

    static class c implements IServerCallBack {
        private WeakReference<Context> ˋ;
        private WeakReference<CommentActivity> ˏ;
        private WeakReference<AddCommentTitle> ॱ;

        public c(Context context, CommentActivity commentActivity, AddCommentTitle addCommentTitle) {
            this.ˋ = new WeakReference(context);
            this.ˏ = new WeakReference(commentActivity);
            this.ॱ = new WeakReference(addCommentTitle);
        }

        public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
        }

        public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
            Context context = (Context) this.ˋ.get();
            AddCommentTitle addCommentTitle = (AddCommentTitle) this.ॱ.get();
            if (context != null && responseBean != null && addCommentTitle != null) {
                int i;
                addCommentTitle.setCommentLayoutStatus(true);
                if (responseBean.getResponseCode() == 3) {
                    i = h.ᐝʽ;
                } else if (responseBean.getResponseCode() == 0 && (responseBean instanceof AddCommentResBean)) {
                    i = ॱ((AddCommentResBean) responseBean, (bcr) o_cvu, context);
                } else {
                    i = h.ॱﾟ;
                }
                ckv.ˎ(context.getResources().getString(i), 0);
                CommentActivity commentActivity = (CommentActivity) this.ˏ.get();
                if (commentActivity != null && responseBean.getRtnCode_() == 0) {
                    commentActivity.ˏ(103);
                    commentActivity.finish();
                }
            }
        }

        private int ॱ(AddCommentResBean addCommentResBean, bcr o_bcr, Context context) {
            int i;
            if (addCommentResBean.getRtnCode_() == 0) {
                Intent intent = new Intent("com.huawei.appmarket.service.broadcast.CommentAdded");
                intent.putExtra("ACTION_PARAM_COMMENT_ADDED_TYPE_APPID", o_bcr.ˊ());
                intent.putExtra("ACTION_PARAM_COMMENT_REPLY_ADDED_TYPE_COMMENTID", addCommentResBean.commentId_);
                intent.putExtra("ACTION_PARAM_COMMENT_ADDED_TYPE_RATING", o_bcr.ˎ());
                intent.putExtra("ACTION_PARAM_COMMENT_ADDED_TYPE_CONTENT", o_bcr.ˏ());
                ll.ˏ(context).ˋ(intent);
                i = h.ॱˉ;
                bcb.ˋ.ˋ("CommentViewControl", "notifyResult, ACTION_COMMENT_ADDED, lastCommentID:" + addCommentResBean.commentId_);
            } else if (addCommentResBean.getRtnCode_() == 1) {
                i = h.ॱꓸ;
            } else if (addCommentResBean.getRtnCode_() == 2) {
                i = h.ˑ;
            } else if (addCommentResBean.getRtnCode_() == 3) {
                i = h.ॱᶥ;
            } else if (addCommentResBean.getRtnCode_() == 4) {
                bdr.ˋ();
                i = h.ˊˋ;
            } else {
                i = h.ˊˋ;
            }
            bcb.ˋ.ˋ("CommentViewControl", "getCommentResId RtnCode:" + addCommentResBean.getRtnCode_());
            return i;
        }
    }

    public bdw(bck o_bck, Context context, CommentActivity commentActivity) {
        this.ᐝ = o_bck;
        this.ͺ = context;
        this.ˋॱ = commentActivity;
        this.ᐝॱ = new String[]{context.getResources().getString(h.ˊᐝ), context.getResources().getString(h.ˋˊ), context.getResources().getString(h.ˊˊ), context.getResources().getString(h.ˉ), context.getResources().getString(h.ˋˋ), context.getResources().getString(h.ˌ)};
    }

    public void ˊ(AddCommentTitle addCommentTitle) {
        this.ॱˋ = addCommentTitle;
    }

    public void ˊ(Intent intent) {
        this.ˏॱ = true;
        Bundle extras = intent.getExtras();
        if (extras != null) {
            String string = extras.getString("APP_NAME");
            String string2 = extras.getString("APP_ICON");
            this.ˊ = extras.getString("PACKAGE_NAME");
            this.ॱ = extras.getString("APP_ID");
            this.ˎ = extras.getString("VERSION_NAME");
            this.ˋ = extras.getString("VERSION_CODE");
            this.ˏ = extras.getString("COMMENT_ID");
            this.ॱॱ = extras.getString("COMMENT_CONTENT");
            this.ʼ = Float.valueOf(extras.getFloat("COMMENT_RATING"));
            ˊ();
            this.ᐝ.ˏ(this.ॱॱ);
            this.ʽ = extras.getString("COMMENT_CONTENT");
            this.ʻ = extras.getInt("LIST_ID");
            this.ᐝ.ॱ(string);
            this.ᐝ.ˋ(string2);
            this.ᐝ.ˎ(this.ᐝॱ[new SecureRandom().nextInt(6)]);
        }
    }

    private void ˊ() {
        if (this.ʼ.floatValue() != 0.0f) {
            Object ˏ = ˏ(this.ʼ.floatValue());
            if (!(TextUtils.isEmpty(ˏ) || this.ˊॱ == null)) {
                this.ᐝ.ˊ(ˏ);
                this.ˊॱ.setRating(this.ʼ.floatValue());
            }
            if (this.ॱˋ != null && this.ॱˊ != null) {
                this.ॱˋ.setImageViewStatus(this.ॱˊ.getText().toString(), this.ʼ.floatValue());
            }
        }
    }

    public void ˎ() {
        Object obj = "";
        if (this.ॱˊ != null) {
            obj = this.ॱˊ.getText().toString();
        }
        if (TextUtils.isEmpty(obj)) {
            bdc.ˊ().ˋ(this.ॱ, this.ˋ);
            return;
        }
        String trim = obj.trim();
        if (!trim.equals(this.ʽ) && !this.ʻॱ) {
            CommentsCache commentsCache = new CommentsCache();
            commentsCache.ˎ(this.ॱ);
            commentsCache.ˏ(this.ˋ);
            commentsCache.ॱ(cev.ॱ(trim));
            bdc.ˊ().ˋ(this.ॱ, this.ˋ);
            bdc.ˊ().ˊ(commentsCache);
        }
    }

    public void ˎ(HwEditText hwEditText) {
        this.ॱˊ = hwEditText;
        this.ॱˊ.addTextChangedListener(this);
    }

    public void ॱ(RatingBar ratingBar) {
        this.ˊॱ = ratingBar;
        this.ˊॱ.setOnRatingBarChangeListener(this);
    }

    public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
    }

    public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        if (!(this.ॱˋ == null || this.ˊॱ == null)) {
            this.ॱˋ.setImageViewStatus(charSequence.toString(), this.ˊॱ.getRating());
        }
        if (this.ˏॱ && this.ॱˊ != null && !TextUtils.isEmpty(this.ॱˊ.getText()) && i2 != 0) {
            this.ˏॱ = false;
            this.ॱˊ.setSelection(this.ॱˊ.getText().length());
        }
    }

    public void afterTextChanged(Editable editable) {
    }

    public void onRatingChanged(RatingBar ratingBar, float f, boolean z) {
        if (z) {
            Object ˏ = ˏ(f);
            if (!TextUtils.isEmpty(ˏ)) {
                this.ᐝ.ˊ(ˏ);
            }
            if (this.ॱˋ != null && this.ˊॱ != null && this.ॱˊ != null) {
                this.ॱˋ.setImageViewStatus(this.ॱˊ.getText().toString(), this.ˊॱ.getRating());
            }
        }
    }

    private String ˏ(float f) {
        if (ˏ(f, 0)) {
            return this.ͺ.getString(h.ˏˎ);
        }
        if (ˏ(f, 1)) {
            return this.ͺ.getString(h.ˈॱ);
        }
        if (ˏ(f, 2)) {
            return this.ͺ.getString(h.ˋʼ);
        }
        if (ˏ(f, 3)) {
            return this.ͺ.getString(h.ˊʽ);
        }
        if (ˏ(f, 4)) {
            return this.ͺ.getString(h.ˋʽ);
        }
        if (ˏ(f, 5)) {
            return this.ͺ.getString(h.ˋʻ);
        }
        return null;
    }

    private static boolean ˏ(float f, int i) {
        if (Math.abs(f - ((float) i)) < 1.0E-7f) {
            return true;
        }
        return false;
    }

    private void ॱ() {
        String str;
        boolean z = false;
        if (!TextUtils.isEmpty(this.ˊ)) {
            z = ((cdg) cdb.ॱ(cdg.class)).ॱॱ(this.ˊ);
        }
        if (z) {
            str = "02";
        } else {
            str = KeyAndValue.NUMBER_01;
        }
        cdk.ॱ(this.ͺ, cdk.ˏ(this.ͺ, h.ॱꞌ), str + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.ॱ);
    }

    public void ˋ() {
        String str;
        if (this.ॱˋ != null) {
            this.ॱˋ.setCommentLayoutStatus(false);
        }
        ॱ();
        Object obj = "";
        if (this.ॱˊ != null) {
            obj = this.ॱˊ.getText().toString();
        }
        if (TextUtils.isEmpty(obj)) {
            str = "";
        } else {
            str = obj.trim();
        }
        if (bdo.ˋ(d.COMMENT_PUBLISH, str)) {
            ckv.ˎ(this.ͺ.getString(h.ॱꓸ), 0);
            return;
        }
        cvt o_bcr = new bcr(this.ˎ);
        o_bcr.ˊ(this.ॱ);
        o_bcr.ˋ(str);
        o_bcr.ʼ(this.ˏ);
        if (this.ˊॱ != null) {
            o_bcr.ॱ(String.valueOf(this.ˊॱ.getRating()));
        }
        o_bcr.ॱ(this.ʻ);
        o_bcr.setServiceType_(cdh.ˎ(this.ˋॱ));
        cfw.ˎ(o_bcr, new c(this.ͺ, this.ˋॱ, this.ॱˋ));
        bdc.ˊ().ˋ(this.ॱ, this.ˋ);
        this.ʻॱ = true;
    }
}
